import { navigationBarOptions } from './global.js'
export default {
    onShareAppMessage(res) { //发送给朋友
		// 获取加载的页面
		let pages = getCurrentPages()
		// 获取当前页面的对象
		let curPage = pages[pages.length - 1];
		//分享的页面路径
		let route = curPage.route
		let options = curPage.options
		
		let query = ""
		for(let key in options) {
			query += key + "=" + options[key] + "&"
		}
		if(query.lastIndexOf("&") != -1) {
			query = query.substring(0, query.lastIndexOf("&"))
		}
		
        return {
			title: navigationBarOptions && navigationBarOptions.navigationBarTitle ? navigationBarOptions.navigationBarTitle:"",
			path: query ? (route + "?" + query):(route)
		}
    },
    onShareTimeline(res) {//分享到朋友圈
		// 获取加载的页面
		let pages = getCurrentPages()
		// 获取当前页面的对象
		let curPage = pages[pages.length - 1];
		//分享的页面路径
		let route = curPage.route
		let options = curPage.options
		
		let query = ""
		for(let key in options) {
			query += key + "=" + options[key] + "&"
		}
		if(query.lastIndexOf("&") != -1) {
			query = query.substring(0, query.lastIndexOf("&"))
		}
		
        return {
			title: navigationBarOptions && navigationBarOptions.navigationBarTitle ? navigationBarOptions.navigationBarTitle:"",
			query: query
		}
    }
}